package com.loper7.base.adapter;

import android.content.Context;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;
import android.widget.GridView;

import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;
import com.loper7.base.R;

/**
 * @author loper7
 * @date 2017/4/21 16:02
 * @Description: ${todo}
 */
public class EasyRecyclerAdapter<T> extends RecyclerArrayAdapter<T> {
    public EasyRecyclerAdapter(Context context) {
        super(context);
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return null;
    }

    public void setOnMoreShowListener(final OnMoreShowListener onMoreShowListener) {
        setMore(R.layout.view_more_show, new OnMoreListener() {
            @Override
            public void onMoreShow() {
                onMoreShowListener.onMoreShow();
            }

            @Override
            public void onMoreClick() {

            }
        });
    }

    public void setOnMoreClickListener(final OnMoreClickListener onMoreClickListener) {
        setMore(R.layout.view_more_click, new OnMoreListener() {
            @Override
            public void onMoreShow() {

            }

            @Override
            public void onMoreClick() {
                onMoreClickListener.onMoreClick();
            }
        });
    }

    /**
     * 设置没有更多数据
     */
    public void showNoMore() {
        setNoMore(R.layout.view_no_more);
    }

    public interface OnMoreShowListener {
        void onMoreShow();
    }

    public interface OnMoreClickListener {
        void onMoreClick();
    }


    public void setLoadMoreViewSpanSizeLookup(RecyclerView recyclerView) {
        if (recyclerView == null) {
            return;
        }
        RecyclerView.LayoutManager manager = recyclerView.getLayoutManager();
        if (manager instanceof GridLayoutManager) {
            ((GridLayoutManager) manager).setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
                @Override
                public int getSpanSize(int position) {
                    if (getAllData().size() <= position)
                        return 2;
                    else
                        return 1;
                }
            });
        }
    }

}
